<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" template="/template/template.xhtml"
	xmlns:s="http://sduept.security.el/func">
	<ui:define name="head">
		<link rel="stylesheet"
			href="/resources/plugins/datatables/dataTables.bootstrap.css" />
		<style>
			.ui-treetable-scrollable-header-box {
			    margin-left: 0px;
			    margin-right: 15px !important;
			}
			body .demo-class .layui-layer-title{background:#c00; color:#fff; border: none;}
body .demo-class .layui-layer-btn{border-top:1px solid #E9E7E7}
body .demo-class .layui-layer-btn a{background:#333;}
body .demo-class .layui-layer-btn .layui-layer-btn1{background:#999;}
		</style>
	</ui:define>
	<ui:define name="content">
		<p:confirmDialog global="true" showEffect="fade" hideEffect="fade">
			<p:commandButton value="是" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
			<p:commandButton value="否" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
		</p:confirmDialog>
		<div id="headDiv" class="box box-solid with-border">
			<h:form id="headForm">
				<p:growl id="msgs" showDetail="true" />
				<div class="box-header"  id="queryDiv">
					<p:outputLabel value="评价计划：" style="margin-left:5px;margin-right:5px"/>
					<p:autoComplete placeholder="输入拼音首字母可查" scrollHeight="400" dropdown="true" 
						var="p" itemLabel="#{p.name}" itemValue="#{p.id}" 
						completeMethod="#{waitingTaskController.complateInspectionPlan}" >
						<p:ajax event="itemSelect" update=":form:dataTb"
							listener="#{waitingTaskController.changeSelectPlan}" oncomplete="getTableScrollHeight()" />
					</p:autoComplete>
					<!-- 
					<p:commandButton value="下载模板" ajax="false"
						icon="ui-icon-arrowthick-1-s" style="margin-left:10px;"
						actionListener="#{waitingTaskController.downLoadTemplate()}">
						<p:fileDownload value="#{waitingTaskController.exportFile}" />
					</p:commandButton> -->
				</div>
			</h:form>
		</div>
		<div id="infoDiv" class="box box-solid with-border">
			<h:form id="form" >
				<p:treeTable id="dataTb" widgetVar="dataTb" value="#{waitingTaskController.root}" var="todo" scrollable="true" emptyMessage="无记录">
					<p:ajax event="expand" listener="#{waitingTaskController.onNodeExpand}" />
					<p:column headerText="名称"  style="width:20%">
						<h:outputText value="#{todo.name} " title="#{todo.name}"/>
					</p:column>
					<p:column headerText="负责人">
						<h:outputText value="#{todo.responsible}"   />
					</p:column>
					<p:column headerText="创建人">
						<h:outputText value="#{todo.creator}"   />
					</p:column>
					<p:column headerText="专家">
						<h:outputText value="#{todo.expert}" />
					</p:column>
					<p:column headerText="计划开始日期">
						<h:outputText value="#{todo.startTime}">
							<f:convertDateTime pattern="yyyy-MM-dd" timeZone="GMT+8"/>  
						</h:outputText>
					</p:column>
					<p:column headerText="计划结束日期">
						<h:outputText value="#{todo.endTime}">
							<f:convertDateTime pattern="yyyy-MM-dd" timeZone="GMT+8"/>  
						</h:outputText>
					</p:column>
					<p:column headerText="实际开始日期">
						<h:outputText value="#{todo.actualStratTime}">
							<f:convertDateTime pattern="yyyy-MM-dd" timeZone="GMT+8"/>  
						</h:outputText>
					</p:column>
					<p:column headerText="实际计划结束日期">
						<h:outputText value="#{todo.actualEndTime}">
							<f:convertDateTime pattern="yyyy-MM-dd" timeZone="GMT+8"/>  
						</h:outputText>
					</p:column>
					<p:column headerText="状态" >
						<h:outputText  style="color:#{waitingTaskController.statusColor}" value="#{waitingTaskController.getStatusStr(todo.type,todo.status)}"/>
					</p:column>
					<p:column headerText="操作" style="text-align:center">
						<p:commandLink rendered="#{waitingTaskController.addStationInfoDialogRendered(todo)}" class="fa fa-list" style="margin-right:15px"
							actionListener="#{waitingTaskController.preOpenAddStationInfoDialog(todo)}" 
							update=":addStationInfoForm:addStationInfoDialog" title="详细" oncomplete="PF('addStationInfoDialog').show()">							
						</p:commandLink>
						
						<p:commandLink  rendered="#{waitingTaskController.inspectBtnRendered(todo)}"  class="fa fa-pencil"
							actionListener="#{waitingTaskController.openInspectionStationDetail2(todo)}" title="评价">							
						</p:commandLink>
						<p:remoteCommand name="onDetailDialogReturn" actionListener="#{waitingTaskController.onDetailDialogReturn}" oncomplete="getTableScrollHeight()"/>
						<p:commandLink rendered="#{waitingTaskController.inspectBtnRendered(todo)}" style="margin-left:15px" class="fa fa-arrow-down"
							title="导出" actionListener="#{waitingTaskController.exportStationExcel(todo)}" ajax="false">
							<p:fileDownload value="#{waitingTaskController.exportFile}" />
						</p:commandLink>
						<p:commandLink style="margin-left:15px" class="fa fa-arrow-up" rendered="#{waitingTaskController.inspectBtnRendered(todo)}"
							title="导入" actionListener="#{waitingTaskController.chooseExcelFile(todo)}" />
						<p:commandLink style="margin-left:15px" class="fa fa-refresh" rendered="#{waitingTaskController.inspectBtnRendered(todo)}"
							title="一键生成整改计划" update="form1" actionListener="#{waitingTaskController.preGenRectificationPlan(todo)}" oncomplete="PF('rectificationPlanDlg').show()" />
					</p:column>
				</p:treeTable>
			</h:form>
			<!-- 生成整改计划 -->
			<h:form id='form1'>
				<p:dialog header="整改计划重新生成" widgetVar="rectificationPlanDlg" id="rectificationPlanDlg" width="688" height="261">
					<p:toolbar>
						<f:facet name="left">
							<p:commandButton value="确定" actionListener="#{waitingTaskController.regenRectificationPlan()}" oncomplete="PF('rectificationPlanDlg').hide()" update=":headForm:msgs" />
						</f:facet>
					</p:toolbar>
					<p:panelGrid styleClass="border:0px;">
						<p:row>
							<p:column style="font-weight: bold;">
								整改负责人<font style="color: red">*</font>
							</p:column>
							<p:column>
								<p:autoComplete scrollHeight="400" dropdown="true"
									value="#{waitingTaskController.createTrackDemo.personInChargeName}"
									var="p" itemLabel="#{p.name}" itemValue="#{p.id}"
									completeMethod="#{waitingTaskController.completePersonInCharge}" >
									<p:ajax event="itemSelect" update="pPhone"
										listener="#{waitingTaskController.onChargePersonSelected}"/>
								</p:autoComplete>
							</p:column>
							<p:column style="font-weight: bold;">
								联系方式<font style="color: red">*</font>
							</p:column>
							<p:column>
								<p:inputText id="pPhone" required="true" requiredMessage="联系方式不允许为空" value="#{waitingTaskController.createTrackDemo.personInChargePhone}" />
							</p:column>
						</p:row>
						<p:row>
							<p:column style="font-weight: bold;">
								整改计划开始时间<font style="color: red">*</font>
							</p:column>
							<p:column>
								<p:calendar required="true" requiredMessage="开始时间不允许为空" pattern="yyyy-MM-dd HH:mm:ss" value="#{waitingTaskController.createTrackDemo.planStartDate}" />
							</p:column>
							<p:column style="font-weight: bold;">
								整改计划结束时间<font style="color: red">*</font>
							</p:column>
							<p:column>
								<p:calendar required="true" requiredMessage="开始时间不允许为空" pattern="yyyy-MM-dd HH:mm:ss" value="#{waitingTaskController.createTrackDemo.planFinishDate}" />
							</p:column>
						</p:row>
					</p:panelGrid>
				</p:dialog>
			</h:form>
			
			<!-- 上传方式选择框 -->
			<h:form>
				<p:dialog header="选择导入方式" widgetVar="dlg1" width="350px" height="200px">
					<p:panelGrid styleClass="border:0px;">
						<p:row>
							<p:column>
								<p:commandButton value="删除原数据并导入" actionListener="#{waitingTaskController.preUpload()}" onclick="PF('fileUploadDialog').show()" />
							</p:column>
						</p:row>
						<p:row>
							<p:column>
								<p:commandButton value="合并原数据并导入" onclick="PF('fileUploadDialog').show()" />
							</p:column>
						</p:row>
						<p:row>
							<p:column>
								<p:commandButton value="取消上传操作" onclick="PF('dlg1').hide()" />
							</p:column>
						</p:row>
					</p:panelGrid>
				</p:dialog>
			</h:form>
			
			<h:form>
				<p:dialog header="上传文件" widgetVar="fileUploadDialog" modal="true" id="fileUploadDialog" width="640" height="200">
					<p:fileUpload style="margin-top:10px" cancelLabel="取消"  allowTypes="/(\.|\/)(zip)$/"
						oncomplete="afterUpload();" update=":headForm:msgs :form:dataTb" onstart="openLoadingDlg();"
						fileUploadListener="#{waitingTaskController.handleFileUpload}" uploadLabel="上传" label="文件" />
				</p:dialog>
			</h:form>
			
			
			<!-- 添加检查详细信息弹窗 -->
			<h:form id="addStationInfoForm">
				<p:dialog id="addStationInfoDialog" widgetVar="addStationInfoDialog" modal="true">
					<p:toolbar>
						<f:facet name="left">
							<p:commandButton value="保存" 
								disabled="#{!waitingTaskController.currentExpertlogin}"
								actionListener="#{waitingTaskController.save()}" update="form:dataTb :headForm:msgs" />
						</f:facet>
					</p:toolbar>
					<p:panelGrid style="text-align:center;">
						<p:row>
							<p:column style="background-color:#eee">
								<h:outputLabel value="专家派出分子公司："></h:outputLabel>
							</p:column>
							<p:column colspan="3">
								<h:outputText value="#{waitingTaskController.selectedWaitingModel.inspectionScope}"></h:outputText>
							</p:column>
						</p:row>
						<p:row>
							<p:column style="background-color:#eee">
								<h:outputLabel value="派出专家分子公司联系人："></h:outputLabel>
							</p:column>
							<p:column>
								<h:outputText value="#{waitingTaskController.selectedWaitingModel.inspectionScopePersonnel}"></h:outputText>
							</p:column>
							<p:column style="background-color:#eee">
								<h:outputLabel value="联系电话："></h:outputLabel>
							</p:column>
							<p:column>
								<h:outputText value="#{waitingTaskController.selectedWaitingModel.inspectionScopePersonnelPhone}"></h:outputText>
							</p:column>
						</p:row>
						<p:row>
							<p:column style="background-color:#eee">
								<h:outputLabel value="被检分子公司："></h:outputLabel>
							</p:column>
							<p:column>
								<h:outputText value="#{waitingTaskController.selectedWaitingModel.acceptScope}"></h:outputText>
							</p:column>
							<p:column style="background-color:#eee">
								<h:outputLabel value="被检单位："></h:outputLabel>
							</p:column>
							<p:column>
								<h:outputText value="#{waitingTaskController.selectedWaitingModel.acceptunit}"></h:outputText>
							</p:column>
						</p:row>
						<p:row>
							<p:column style="background-color:#eee">
								<h:outputLabel value="被检单位迎检联系人："></h:outputLabel>
							</p:column>
							<p:column>
								<h:outputText value="#{waitingTaskController.selectedWaitingModel.stationPersonnel}"></h:outputText>
							</p:column>
							<p:column style="background-color:#eee">
								<h:outputLabel value="联系电话："></h:outputLabel>
							</p:column>
							<p:column>
								<h:outputText value="#{waitingTaskController.selectedWaitingModel.stationPersonnelPhone}"></h:outputText>
							</p:column>
						</p:row>
						
						<p:row>
							<p:column style="background-color:#eee">
								<h:outputLabel value="派出专家："></h:outputLabel>
							</p:column>
							<p:column>
								<h:outputText value="#{waitingTaskController.selectedWaitingModel.inspectionExpert}"></h:outputText>
							</p:column>
							<p:column style="background-color:#eee">
								<h:outputLabel value="联系电话："></h:outputLabel>
							</p:column>
							<p:column>
								<h:outputText value="#{waitingTaskController.selectedWaitingModel.inspectionExpertPhone}"></h:outputText>
							</p:column>
						</p:row>
						<p:row>
							<p:column style="background-color:#eee">
								<h:outputLabel value="抽检变电站："></h:outputLabel>
							</p:column>
							<p:column colspan="3">
								<p:autoComplete id="stationName" value="#{waitingTaskController.selectedWaitingModel.stationName}" scrollHeight="200"
									disabled="#{!waitingTaskController.currentExpertlogin}"
									completeMethod="#{waitingTaskController.completeSubstations}" dropdown="true" inputStyle="width:100%">
									<!-- <p:ajax event="itemSelect" listener="#{waitingTaskController.onSubstationSelect()}"></p:ajax> -->
									<p:ajax event="keyup"></p:ajax>
								</p:autoComplete>
							</p:column>
							
						</p:row>
						<p:row>
							<p:column style="background-color:#eee">
								<h:outputLabel value="预计检查时间："></h:outputLabel>
							</p:column>
							<p:column colspan="3">
								<p:calendar id="startTime" disabled="#{!waitingTaskController.currentExpertlogin}"
									value="#{waitingTaskController.selectedWaitingModel.startTime}"
									pattern="yyyy-MM-dd" >
									<p:ajax event="dateSelect" />
								</p:calendar>至<p:calendar id="endTime"
									disabled="#{!waitingTaskController.currentExpertlogin}"
									value="#{waitingTaskController.selectedWaitingModel.endTime}"
									pattern="yyyy-MM-dd" >
									<p:ajax event="dateSelect" />
								</p:calendar> 
							</p:column>
						</p:row>
						
						<p:row>
							<p:column style="background-color:#eee">
								<h:outputLabel value="抽检类型："></h:outputLabel>
							</p:column>
							<p:column colspan="3">
								<p:selectOneMenu id="stationType" value="#{waitingTaskController.selectedWaitingModel.stationType}"
									disabled="#{waitingTaskController.hasInspectionItems()}" style="font-weight:bold">
									<f:selectItem itemLabel=""/>
									<f:selectItems value="#{waitingTaskController.getStationTypes()}" var="type" itemLabel="#{type.label}"/>
									<p:ajax event="itemSelect" update="addBtn"/>
								</p:selectOneMenu>
								<p:commandButton id="addBtn" value="生成检查表单" icon="fa fa-plus" style="margin-right:5px;margin-left:5px"
									disabled="#{waitingTaskController.disabledGenerateItemBtn()}"
									actionListener="#{waitingTaskController.generateInspectionItems()}" update="stationType addBtn clearBtn :headForm:msgs"/>
									
								<p:commandButton id="clearBtn" value="重置" icon="fa fa-refresh" 
									disabled="#{waitingTaskController.disabledClearBtn()}"
									actionListener="#{waitingTaskController.clearInspectionItems()}" update="stationType addBtn clearBtn :headForm:msgs" >
									<p:confirm header="提示" message="该操作将清除已有的评价项，确定继续吗？" icon="ui-icon-alert" />
								</p:commandButton>
							</p:column>
						</p:row>
					</p:panelGrid>
				</p:dialog>
			</h:form>
		</div>
	</ui:define>
	<ui:define name="contentend">
		<script src="/resources/plugins/datatables/jquery.dataTables.js"></script>
		<script src="/resources/plugins/datatables/dataTables.bootstrap.min.js"></script>
		<script src="/resources/js/tables/mytable.js"></script>
		<script src="/resources/js/tables/singleScrollTreeTable.js"></script>
		<script>
		function openInspectionStationDetail(path) {
			if (path) {
				layer.open({
					type : 2,
					maxmin : false,
					area : [ '90%', '90%' ],
					fixed : false, //不固定
					title : '评价操作页',
					maxmin : true,
					content : path,
					full: function(layero, index) {
						var body = layer.getChildFrame('body', index);
						//评价操作页的iframe的jQuery对象
                        var mframe = window.top.$('iframe');
                        //计算评价操作页iframe的高度
                        /* var height = ($(mframe).height()/9)*10-50;
                        $(mframe).attr('style','height:'+height+'px'); */
                        //设置滚动的datatable的高度
                        var height = $(mframe).height();
						var dtHeight = height-170;
                        body.find(".ui-datatable-scrollable-body").attr('style','height:'+dtHeight+'px;overflow-y:scroll');
					},
					restore: function(layero, index) {
						var body = layer.getChildFrame('body', index);
						//评价操作页的iframe的jQuery对象
                        var mframe = window.top.$('iframe');
                        //计算评价操作页iframe的高度
                        var height = $(mframe).height();
                        /* var height = ($(mframe).height()/10)*9;
                        $(mframe).attr('style','height:'+height+'px');*/
                        //设置滚动的datatable的高度
						var dtHeight = height-170;
                        body.find(".ui-datatable-scrollable-body").attr('style','height:'+dtHeight+'px;overflow-y:scroll');
					}
				});
			}
		}
		function openLoadingDlg(){
			layer.load({});
		}
		

		function dialogReturn(index,mark){
			var params = [];
			params.push({name:'mark',value:mark});
			onDetailDialogReturn(params);
		}
		function afterUpload() {
			PF('fileUploadDialog').hide();
			PF('dlg1').hide();
			layer.closeAll('loading');
			//layer.close();
			getTableScrollHeight();
		}
		function chooseDialog(flag) {
			if(flag) {
				// true，有已经评价的标准项
				PF('dlg1').show();
			} else if(!flag){
				// false，均未评价
				PF('fileUploadDialog').show();
			}
		}
		</script>
	</ui:define>
</ui:composition>
